// 对锁进行封装
#pragma once
#include <pthread.h>

class Mutex
{
public:
    Mutex(pthread_mutex_t *mutex = nullptr) : _mutex(mutex)
    {
    }

    void mutex_lock()
    {
        if (_mutex) // 不为空
        {
            pthread_mutex_lock(_mutex);
        }
    }

    void mutex_unlock()
    {
        if (_mutex)
        {
            pthread_mutex_unlock(_mutex);
        }
    }

    ~Mutex()
    {
    }

private:
    pthread_mutex_t *_mutex;
};

class LockGuard
{
public:
    LockGuard(pthread_mutex_t *mutex = nullptr) : _p_mutex(mutex)
    {
        _p_mutex.mutex_lock();
    }

    ~LockGuard()
    {
        _p_mutex.mutex_unlock();
    }

private:
    Mutex _p_mutex;
};
